package com.jy.api.controller.admin;

import com.jy.api.dao.ElectronicBillDao;
import com.jy.api.domain.ElectronicBill;
import com.jy.api.service.ElectronicBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lihu on 2017/11/5.
 */
@Slf4j
@RestController
@RequestMapping(value = "v1/admin/", produces = "application/json;charset=utf-8")
public class ShopPaymentController {


    @Autowired
    ElectronicBillService electronicBillService;

    /**
     * 查询第三方支付对账单
     *
     * @param storeId
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "third-party")
    public ResponseEntity getThirdParty(@RequestParam(name = "storeId") String storeId, @RequestParam("from") String from, @RequestParam("to") String to,
                                        @PageableDefault(value = 10, sort = {"date"}, direction = Sort.Direction.DESC) Pageable pageable) {
        try {
            return new ResponseEntity(electronicBillService.findTotalAmount(storeId, from, to, pageable), HttpStatus.OK);
        } catch (Exception ex) {
            log.error("getProductTypes is error=>storeId:{}", storeId, ex);
            return new ResponseEntity("系统运行错误", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}
